﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CodeGenerator.Models;
using CodeGenerator.Util;

namespace CodeGenerator.Template.DAL.Dal
{
    public partial class DAL : ITemplate
    {
        public MetaData Data { get; set; }
        public List<LookupClassModel> lookups { get; set; }
        public List<PickupListModel> pickuplist { get; set; }

        public string Filename
        {
            get { return "{ClassName}DAL.cs"; }
        }
        public string FolderName
        {
            get { return ""; }
        }


        /// <summary>
        /// Create by: Nathawat (11-05-2014)
        /// provide method for check Class has GeoLocation attribute
        /// </summary>
        /// <param name="model">Class Model</param>
        /// <returns>bool</returns>
        public bool HasGeoLocationAttribute(ClassModel model)
        {
            foreach (AttributeModel attribute in model._attributes)
            {
                if (attribute.DataType.Name.Equals("GeoLocation"))
                {
                    return true;
                }
            }
            return false;
        }

        public bool IsGenerateOneTime { get { return false; } }
        public bool IsGenerateFolder { get { return false; } }
        public bool IsRequiredOnlyOneMember { get { return true; } }
        public GenerateStyle GenerateStyle { get { return GenerateStyle.Normal; } }

        #region Calendar Search
        public List<EventModel> GetCurrentModel(ClassModel model)
        {
            var result = Data.EventMappers.FindAll(x => x.ClassModel.Id == model.Id);
            return result;
        }

        public ClassModel GetLookupClass(int desAttrId)
        {
            var classmodel = Generators.Generator.GetLookupClassByAttrId(desAttrId);
            return classmodel;
        }
        #endregion
    }
}
